#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@File    ：llm.py
@Author  ：平
@Date    ：2025/10/1 15:29 
"""
from langchain.chat_models import init_chat_model
from langchain_core.language_models import BaseChatModel

from app.config.config import settings


def get_llm(model: str = None, base_url: str = None, api_key: str = None, **kwargs) -> BaseChatModel:
    """
    获取llm
    Args:
        model: 模型配置
        base_url: 基础url
        api_key: 密钥
        **kwargs: 额外配置

    Returns: 基础对话模型

    """
    model = model or settings.MODEL
    base_url = base_url or settings.MODEL_BASE_URL
    api_key = api_key or settings.MODEL_API_KEY
    return init_chat_model(model, base_url=base_url, api_key=api_key, **kwargs)


if __name__ == '__main__':
    llm = get_llm()